<?php
namespace app\model\study;

use think\Model;

class WlogModel extends Model
{
    protected $autoWriteTimestamp = 'int';
    protected $name = 'study_wlog';
    protected $pk = 'id';

    public static function inc($uid,$t) {
        $w = self::where("uid",$uid)->find();
        if ($w == null) {
            // 不存在，加入
            self::createWlog($uid);
        }
        if ((time())-($w->getData("update_time")) < ($t+1)) return;
        $w->time += $t;
        $w->save();
    }

    public static function createWlog($uid) {
        self::create([
            "uid"   => $uid,
            "time"  => 0
        ]);
    }
    public static function getRank() {
        return self::order("time","desc")->select();
    }
}